#include "TypeUnfoldButton.h"
#include "TypeEntryItem.h"
#include "AbstractMappingWindow.h"
#include "TypeEntryItem.h"

#include <QPainter>

TypeUnfoldButton::TypeUnfoldButton( TypeEntryItem* parent )
	:QGraphicsItem( parent )
{
	this->_parent = parent;
	this->_x = _parent->width() / 2 - RADIUS - 20;
	this->_y = _parent->height() / 2 - RADIUS;
	this->_isHover = false;
	this->setAcceptHoverEvents(true);
	this->setFlag(QGraphicsItem::ItemIsFocusable, true);	
}

TypeUnfoldButton::~TypeUnfoldButton(void)
{
}

void TypeUnfoldButton::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget )
{
	if ( this->_isHover )
	{
		painter->setPen(QPen(Qt::NoPen));
		painter->setBrush(QBrush(QColor("#FF7F00")));
		painter->drawEllipse( _x , _y ,RADIUS*2 ,RADIUS*2 );
	}

	QFont sansFont("Helvetica", 10, QFont::Bold );
	painter->setFont(sansFont);
	painter->setPen(QPen(Qt::white));
	painter->drawText( _x , _y ,RADIUS*2,RADIUS*2,Qt::AlignCenter,"+");
}

QRectF TypeUnfoldButton::boundingRect() const
{
	return QRectF( _x, _y ,RADIUS*2,RADIUS*2);
}

void TypeUnfoldButton::hoverEnterEvent( QGraphicsSceneHoverEvent* event )
{
	this->_isHover = true;
	this->update();
}

void TypeUnfoldButton::hoverLeaveEvent( QGraphicsSceneHoverEvent* event )
{
	this->_isHover = false;
	this->update();
}

void TypeUnfoldButton::mousePressEvent( QGraphicsSceneMouseEvent* event )
{
	WOP_Entry* en = this->_parent->getWOPEntry();
	//MappingDialog::getInstance()->createSubTab( this->_parent->getName(), en );
}
